﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[spEliminaDoctor](
	@pnIdDoctor		INT,
	@pnIdLaboratorio INT,
	@pnIdSucursal	INT,
	@psIpMod		VARCHAR(15),
	@pnIdUsuarioMod	INT
)
AS
BEGIN
	SET NOCOUNT ON;

	IF EXISTS(SELECT 1 FROM dbo.CatPaciente WHERE IdDoctor = @pnIdDoctor AND IdLaboratorio = @pnIdLaboratorio AND IdSucursal = @pnIdSucursal)
	BEGIN
		UPDATE	dbo.CatDoctor
		SET		BajaLogica = 1, FechaMod = GETDATE(), IpMod = @psIpMod, IdUsuarioMod = @pnIdUsuarioMod
		WHERE	IdDoctor = @pnIdDoctor AND IdLaboratorio = @pnIdLaboratorio AND IdSucursal = @pnIdSucursal
	END
	ELSE
	BEGIN
		DELETE FROM dbo.CatDoctor WHERE IdDoctor = @pnIdDoctor and IdLaboratorio = @pnIdLaboratorio
	END
	
	SET NOCOUNT OFF;
END